var path = require('path'),
  fs = require('fs');

module.exports = {

  initData: function (cb) {

    var dictFile = fs.readFileSync(process.cwd() + '/api/models/dict.csv', 'utf8');

    DataDict.destroy().exec(function () {

      var dictLines = dictFile.split('\n');

      async.forEach(dictLines, function (line, callback) {
        var columns = line.split(',');
        if (columns.length < 3) {
          return callback();
        }
        var dict = {
          dictType: columns[0].trim(),
          code: columns[1].trim(),
          dictVal: columns[2].trim(),
        };

        DataDict.create(dict).exec(function () {

          callback(); // tell async that the iterator has completed

        });


      }, function (err) {
        //console.log('iterating done');
        return cb(err);
      });

    });
  }
};



